package panel.mainPanel
{
	import assists.TextFieldUtils;
	
	import com.greensock.TweenLite;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	public class TextGroupList extends Sprite
	{
		private var _stage:Stage;
		
		private var _width:Number = 0;
		private var _height:Number = 0;
		
		private var textList:Array;
		
		private var showDetail:Function;
		
		public function TextGroupList(stage:Stage,wid:Number,hei:Number)
		{
			_stage = stage;
			
			_width = wid;
			_height = hei;
			
			textList = [];
		}
		
		public function createText(list:Array):void
		{
			for(var i:int = 0;i < list.length;i++){
//				var text:TextField = new TextField();
//				text.autoSize = TextFieldAutoSize.LEFT;
//				text.multiline = true;
//				text.wordWrap = true;
//				
//				TextFieldUtils.setHtmlText(text,list[i],true);
//				text.width = _width;
//				text.height = text.textHeight + 2;
//				text.mouseEnabled = false;
//				this.addChild(text);
				
				var obj:TextBox = new TextBox(_stage,_width,_height);
				obj.clickFunc = showDetail;
				obj.changeData(list[i]);
				
				this.addChild(obj);
				
				textList.push(obj);
				obj.x = 0;
				obj.y = _height + 10;
			}
			
			changeData(0);
		}
		
		public function changeData(num:int):void
		{
			for(var i:int = 0;i < textList.length;i++){
				if(i < num){
					TweenLite.to(textList[i],0.5,{y: - textList[i].height * 1.5});
				}if(i == num){
					TweenLite.to(textList[i],0.5,{y:0});
				}if(i > num){
					TweenLite.to(textList[i],0.5,{y: _height + 10});
				}
				
				textList[i].clearRecord();
			}
		}
		
		public function set clickAndShowDetail(func:Function):void
		{
			showDetail = func;
		}
		
		public function clear():void
		{
			for(var i:int = 0;i < textList.length;i++){
				textList[i].clear();
			}
		}
	}
}